<?php

/**

 * Created by PhpStorm.

 * User: win7

 * Date: 2018/5/10 0010

 * Time: 11:12

 */



namespace Wx\Controller;

use Think\Controller;



class StoreMemberController extends Controller

{

    public function Index(){

        $store = M('shop_store');

        $area = M('area');

        $community = M('shop_community');



        $storeid = session('s_id');

        $store_info = $store->where("id = {$storeid}")->find();//获取店铺信息

        $community_info = $community->where("id = {$store_info['c_id']}")->find();//获取店铺绑定小区



        //获取地址area

        if($community_info['a_id_1']>0)$a_id_1 = $area->where("id = {$community_info['a_id_1']}") ->field('name')->find();

        if($community_info['a_id_2']>0)$a_id_2 = $area->where("id = {$community_info['a_id_2']}") ->field('name')->find();

        if($community_info['a_id_3']>0)$a_id_3 = $area->where("id = {$community_info['a_id_3']}") ->field('name')->find();

        $community_info['a_id_1'] = $a_id_1['name'];

        $community_info['a_id_2'] = $a_id_2['name'];

        $community_info['a_id_3'] = $a_id_3['name'];



        $usermodel = new UserController();

        $poststore = I("post.");

        if ($poststore){

            foreach($poststore as $k => $v){

                if ($v == ''){

                    unset($poststore[$k]);

                }

                if ($store_info[$k] == $v){

                    unset($poststore[$k]);

                }

            }

            if ($poststore){

                $savestore = $store->where("id = {$storeid}")->save($poststore);

                if ($savestore){

                    $this->success($usermodel->user());

                }else{

                    $this->error('保存失败');

                }

            }else{

                $this->error($usermodel->user());

            }//end if post



        }//end if post



        $this->assign('store',$store_info);

        $this->assign('community',$community_info);

        $this->display('information-sj');

    }//end fun index

}//end class